package com.ikun.service.impl;

import com.ikun.mapper.UserMapper;
import com.ikun.pojo.DeliveryAddress;
import com.ikun.pojo.User;
import com.ikun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class UserServiceImpl implements UserService {

    @Autowired  // 自动注入UserMapper
    private UserMapper userMapper; // 声明UserMapper的实现类为userMapper，方便在UserService中使用userMapper的功能
    @Override
    public User getUserByUsernameAndPassword(String username, String password) {
        return userMapper.getUserByUsernameAndPassword(username, password);
    }

    @Override
    public int addUser(String username, String password) {
        return userMapper.addUser(username, password);
    }

    @Override

    //根据用户id查询其收货地址
    public List<DeliveryAddress> getAddressesByUserId(Integer userId) {
        return userMapper.getAddressesByUserId(userId);
    }

    @Override
    public int addAddress(DeliveryAddress deliveryAddress) {
        return userMapper.addAddress(deliveryAddress.getUserId(), deliveryAddress.getDeliveryAddress(),
                deliveryAddress.getPhoneNumber(), deliveryAddress.getContactName(),
                deliveryAddress.getSex(), deliveryAddress.getTag(), deliveryAddress.getDoorPlate());

    }

    @Override
    public int updateAddressByAddressId(DeliveryAddress deliveryAddress) {
        return userMapper.updateAddress(deliveryAddress.getAddressId(), deliveryAddress.getDeliveryAddress(),
                deliveryAddress.getPhoneNumber(), deliveryAddress.getContactName(),
                deliveryAddress.getSex(), deliveryAddress.getTag(), deliveryAddress.getDoorPlate());
    }
    @Override
    public int deleteAddressByAddressId(Integer addressId) {
        return userMapper.deleteAddress(addressId);
    }
    @Override
    public User getUserById(Integer id){
        return userMapper.getUserById(id);
    }

    @Override
    public void updateNameByUserId(Integer userId , String name) {
        userMapper.updateNameByUserId(userId, name);

    }
    @Override
    public void updateBriefIntroductionByUserId(Integer userId, String briefIntroduction) {
        userMapper.updateBriefIntroductionByUserId(userId, briefIntroduction);
    }

    @Override
    public void updateUserNameByUserId(Integer userId, String userName) {
        userMapper.updateUserNameByUserId(userId,userName);
    }

    @Override
    public void updateAvatar(Integer userId, String resultUrl) {
        userMapper.updateAvatar(userId,resultUrl);
    }
}
